/**
 * 
 */
var rowNumber;
$(function(){
	   $('#share_table')
		.datagrid(
				{
					url : 'admin/queryAdShareInfo.do?pageSize=10',
					collapsible : true,
					width : '100%',
					height :'350px',
					iconCls : 'icon-user',
					fitColumns : true,
					pagination : true,
					rownumbers : true,
					singleSelect:true,
					checkOnSelect:false,
					selectOnCheck:false,
					loadMsg:'正在加载数据',
					loadFilter:function(data){
						for (var i = 0; i < data.rows.length; i++) {
							if (data.rows[i].projectStatus == 0) {
								data.rows[i].projectStatus = '未开始';
								
							}
							if (data.rows[i].projectStatus == 1) {
								data.rows[i].projectStatus = '进行中';
								
							}
							if (data.rows[i].projectStatus == 2) {
								data.rows[i].projectStatus = '已结束';
							}
						}
						 return data;
					},
					onClickRow: function(rowIndex, rowData) {
						rowNumber = rowIndex;
					},
					onDblClickRow :function(rowIndex,rowData){
						//layer.msg("double click");
					  },
					onLoadSuccess:function(data){
						$('#share_table').datagrid('selectRow',rowNumber);
					},
					toolbar:'#toolbar',
					columns : [ [
							{
								field : 'projectTitle',
								title : '项目名',
								width : 50,
								align : 'center'
							},
							{
								field : 'projectStatus',
								title : '项目状态',
								width : 50,
								align : 'center'
							},
							{
								field : 'userNickName',
								title : '用户昵称',
								width : 50,
								align : 'center'
							},
							{
								field : 'userTelephone',
								title : '联系方式',
								width : 50,
								align : 'center'
							},
							{
								field : 'shareReadCount',
								title : '分享阅读数量',
								width : 50,
								align : 'center'
							},
							{
								field : 'shareReadMoney',
								title : '所得金额',
								width : 50,
								align : 'center'
							},
							{
								field : 'shareMoneyLimit',
								title : '限制金额',
								width : 50,
								align : 'center'
							}
						   ] ]
				});
	 //设置分页控件  
		
	var p = $('#share_table').datagrid('getPager');
		$(p).pagination({
			pageSize : 10,//每页显示的记录条数，默认为10  
			pageList : [ 5, 10, 20, 30, 40, 50 ],//可以设置每页记录条数的列表  
			beforePageText : '第',//页数文本框前显示的汉字  
			afterPageText : '页    共 {pages} 页',
			displayMsg : '当前显示 {from} - {to} 条记录   共 {total} 条记录',
			onSelectPage : function(pageNumber, pageSize) {
				//layer.msg("pageNumber="+pageNumber+"pageSize="+pageSize)
				var datas = {
					userTelephone : $('#suserTelephone').textbox('getValue'),
					userNickName : $('#suserNickName').textbox('getValue'),
					projectTitle : $('#sprojectTitle').textbox('getValue'),
					currentPage : (pageNumber - 1) * pageSize,
					pageSize : pageSize
				}
				loadData(datas);
			},
			onRefresh : function(pageNumber, pageSize) {
				var datas = {
						userTelephone : $('#suserTelephone').textbox('getValue'),
						userNickName : $('#suserNickName').textbox('getValue'),
						projectTitle : $('#sprojectTitle').textbox('getValue'),
						currentPage : (pageNumber - 1) * pageSize,
						pageSize : pageSize
					}
				loadData(datas);
			}
		});
	});
var loadData = function(datas){
	$.ajax({
		url : 'admin/queryAdShareInfo.do',
		type : "POST",
		dataType : "json",
		data : datas,
		success : function(param) {
			$('#share_table').datagrid('loadData', param);
		}
	});
}
$(function(){
	$('#search').bind('click',function(){
		var pageSize = $('#share_table').datagrid('getPager').data(
		"pagination").options.pageSize;
				var datas = {
					pageSize : pageSize,
					userTelephone : $('#suserTelephone').textbox('getValue'),
					userNickName : $('#suserNickName').textbox('getValue'),
					projectTitle : $('#sprojectTitle').textbox('getValue'),
				}
				loadData(datas);
	});
	$('#reset').bind('click',function(){
		var pageSize = $('#share_table').datagrid('getPager').data("pagination").options.pageSize;
			 $('#suserTelephone').textbox('setValue','');
			 $('#suserNickName').textbox('setValue','');
			 $('#sprojectTitle').textbox('setValue','');
				var datas = {
					pageSize : pageSize,
				}
				loadData(datas);
	});
	
});